﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinFormUI
{
    public partial class frmCreateAccount : Form
    {
        //variables
        NFLDriverLogic drInstance;
        //array of bool values that represent if the values the user input are valid (or at least populated) indexes 0-4 represent if 
        //the textboxes are populated, and index 5 is only true if the passwords match
        bool[] validInput = new bool[6];
        public frmCreateAccount()
        {
            InitializeComponent();
        }
        public void setDrInstance(NFLDriverLogic DRInstance)
        {
            drInstance = DRInstance;
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //ensures all the validInput values are set to false
            string password = txtPassword.Text;
            string passwordReentry = txtReenterPassword.Text;
            for (int i = 0; i < 6; i++)
            {
                validInput[i] = false;
            }
            if (txtFName.Text != "")
            {
                validInput[0] = true;
            }
            if (txtLName.Text != "")
            {
                validInput[1] = true;
            }
            if (txtEmail.Text != "")
            {             
                validInput[2] = true;
            }
            if (txtPassword.Text != "")
            {
                validInput[3] = true;
                if (txtReenterPassword.Text != "")
                {
                    validInput[4] = true;
                    //if (drInstance.isValidPassword(txtPassword.Text))
                    //{
                        if (txtPassword.Text.Equals(txtReenterPassword.Text))
                        {
                            validInput[5] = true;
                        }
                    //}
                }
                
            }

            if (validInput[0])
            {
                if (validInput[1])
                {
                    if (validInput[2])
                    {
                        if (validInput[3])
                        {
                            if (validInput[4])
                            {
                                if (validInput[5])
                                {
                                    drInstance.createAccount(txtFName.Text, txtLName.Text, txtEmail.Text, txtPassword.Text);
                                    this.Close();
                                }
                                else
                                {
                                    MessageBox.Show("Passwords do not match.  Please re-enter your passwords", "Passwords do not match.", MessageBoxButtons.OK);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Invalid password.  Please enter a password that has 2 uppercase letters, 2 lowercase letters, and 2 special characters", "Weak Password", MessageBoxButtons.OK);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please enter a password", "Missing Required Field", MessageBoxButtons.OK);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please enter your email=", "Missing Required Field", MessageBoxButtons.OK);
                    }
                }
                else
                {
                    MessageBox.Show("Please enter your last name", "Missing Required Field", MessageBoxButtons.OK);
                }
            }
            else
            {
                MessageBox.Show("Please enter your first name", "Missing Required Field", MessageBoxButtons.OK);
            }

        }
    }
}
